package com.tengju.bff.infrastructure.export.repo;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tengju.bff.infrastructure.export.convert.BillApplyRecordConvert;
import com.tengju.bff.infrastructure.export.convert.ExportCrmDealerInfoVoConvert;
import com.tengju.bff.infrastructure.export.convert.TableVoConvert;
import com.tengju.bff.interfaces.covercharge.entity.vo.AdminSelfCertificationQueryVo;
import com.tengju.bff.interfaces.covercharge.service.IServiceSelfCertificationWithdrawService;
import com.tengju.bff.interfaces.manage.crm.dealer.facade.ReportDealerInfoFacade;
import com.tengju.bff.interfaces.shared.TableVO;
import com.tengju.bff.interfaces.shared.export.BaseExportQuery;
import com.tengju.bff.interfaces.shared.export.BillApplyRecordExportQuery;
import com.tengju.bff.interfaces.shared.servlet.ManageUtil;
import com.tengju.export.domain.record.ExportDataSourceRepository;
import com.tengju.export.domain.record.Query;
import com.tengju.export.domain.record.Table;
import com.tengju.user.application.user.UserDataAuthService;
import com.tengju.user.domain.model.user.Staff;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: 李大仙
 * @date: 2021/8/23 2:39 下午
 */
@Service("billApplyRecordExportDataSourceRepository")
@RequiredArgsConstructor(onConstructor_ = {@Autowired})
public class BillApplyRecordExportDataSourceRepository implements ExportDataSourceRepository {

    private final IServiceSelfCertificationWithdrawService serviceSelfCertificationWithdrawService;
    private final UserDataAuthService userDataAuthService;

    @Override
    public Table batchFindDataSource(Query query) {
        BillApplyRecordExportQuery exportQuery = (BillApplyRecordExportQuery) query;

        Page<AdminSelfCertificationQueryVo> selfCertificationVoPage = serviceSelfCertificationWithdrawService.queryPageCertification(new Page<>(exportQuery.getPageNo(), exportQuery.getLimit()),
                exportQuery.getIdCode() != null ? exportQuery.getIdCode().toString() : null,
                exportQuery.getUserName(),
                exportQuery.getInvoice(),
                exportQuery.getPlatformCode(),
                exportQuery.getStatus(),
                exportQuery.getStartDate(),
                exportQuery.getEndDate(),
                exportQuery.getType(),
                exportQuery.getExportType());

        //对数据做脱敏处理
        List<AdminSelfCertificationQueryVo> records = userDataAuthService.dataMasking(selfCertificationVoPage.getRecords(), exportQuery.getStaffId());

        return BillApplyRecordConvert.convert(records);
    }
}
